package com.example.mqtt.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.mqtt.entity.Sensor1;
import com.example.mqtt.entity.Sensor2;
import com.example.mqtt.entity.Sensor3;
import com.example.mqtt.entity.Sensor4;
import com.example.mqtt.mapper.Data1Mapper;
import com.example.mqtt.mapper.Data2Mapper;
import com.example.mqtt.mapper.Data3Mapper;
import com.example.mqtt.mapper.Data4Mapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/data", produces = "application/json;charset=UTF-8")
public class MessageController {
    @Resource
    Data1Mapper data1Mapper;
    @Resource
    Data2Mapper data2Mapper;
    @Resource
    Data3Mapper data3Mapper;
    @Resource
    Data4Mapper data4Mapper;

    @PostMapping("/1")
    public boolean postData1(@RequestBody Sensor1 sensor1) {
        if (null == sensor1) return false;
        data1Mapper.insert(sensor1);
        return true;
    }

    @PostMapping("/2")
    public boolean postData2(@RequestBody Sensor2 sensor2) {
        if (null == sensor2) return false;
        data2Mapper.insert(sensor2);
        return true;
    }

    @PostMapping("/3")
    public boolean postData3(@RequestBody Sensor3 sensor3) {
        if (null == sensor3) return false;
        data3Mapper.insert(sensor3);
        return true;
    }

    @PostMapping("/4")
    public boolean postData4(@RequestBody Sensor4 sensor4) {
        if (null == sensor4) return false;
        data4Mapper.insert(sensor4);
        return true;
    }

    @GetMapping("/1")
    public List<Sensor1> getData1() {
        return data1Mapper.selectList(Wrappers.lambdaQuery());
    }

    @GetMapping("/2")
    public List<Sensor2> getData2() {
        return data2Mapper.selectList(Wrappers.lambdaQuery());
    }

    @GetMapping("/3")
    public List<Sensor3> getData3() {
        return data3Mapper.selectList(Wrappers.lambdaQuery());
    }

    @GetMapping("/4")
    public List<Sensor4> getData4() {
        return data4Mapper.selectList(Wrappers.lambdaQuery());
    }
}
